package com.guodefu.unifiedresponse;

import com.guodefu.unifiedresponse.exception.BusinessException;
import java.text.MessageFormat;

/**
 * 异常帮助类，更方便的抛出定制的 BusinessException
 *
 * @author guodefu909
 */
public interface ExceptionAssert extends IResult, Assert {

    /**
     * 抛出定制的 BusinessException
     */
    @Override
    default void throwBusinessException(Object... args) {
        String msg = null;
        if (args.length > 0) {
            msg = MessageFormat.format(getMessage(), args);
        }
        throw BusinessException.instance(this, msg);
    }

    /**
     * 抛出定制的 BusinessException
     */
    @Override
    default void throwBusinessException(Throwable t, Object... args) {
        String msg = null;
        if (args.length > 0) {
            msg = MessageFormat.format(getMessage(), args);
        }
        throw BusinessException.instance(this, msg, t);
    }

}
